module nade.time;

import std.perf;
import std.math;


private PerformanceCounter _counter = null;
private double _frameTime = 0;
private double _curTime = 0;
private double _prevTime = 0;
private bool _paused = false;


double actualTime()
{
	if(_counter is null)
	{
		_counter = new PerformanceCounter();
		_counter.start;
	}
	
	_counter.stop;

	return _counter.microseconds()/1000000.0;
}

void pauseTime()
{
	_paused = true;
}

void resumeTime()
{
	_paused = false;
	_prevTime = _curTime = actualTime;
}

bool updateTime()
{
	if(!_paused)
	{
		if((_frameTime = actualTime-_prevTime) > 0)
		{
			_prevTime += _frameTime;
			_curTime += _frameTime;
			return true;
		}
	}

	return false;
}

double curTime()
{
	return _curTime;
}

double frameTime()
{
	return _frameTime;
}
